package com.itheima.mString;

import java.util.Scanner;

/*
    身份证校验
 */
public class Work08 {
    public static void main(String[] args) {
        //输入身份证
        Scanner sc = new Scanner(System.in);
        System.out.println("输入身份证号码:");
        String IDNum = sc.next();
        System.out.println("是否合法"+islegal(IDNum));
    }

    public static boolean islegal(String IDNum) {
        boolean islegal = false;
        //18位
        if (IDNum.length() != 18 || IDNum.startsWith("0")) {
            islegal = false;
        } else {
            char[] chs = IDNum.toCharArray();
            for (int i = 0; i < chs.length; i++) {
                if (chs[i] < '0' || chs[i] > '9') {
                    islegal = false;
                } else if (i == chs.length - 1) {
                    if (chs[i] == 'X' || (chs[i] >= '0' || chs[i] <= '9')) {
                        islegal = true;
                    }
                }
            }
        }
        return islegal;
    }
}
